package com.fimuz.mqmeet.api.loginusersetting.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fimuz.mqmeet.api.loginusersetting.dao.LoginusersettingDao;
import com.fimuz.mqmeet.api.loginusersetting.service.LoginusersettingService;
import com.fimuz.mqmeet.api.loginusersetting.service.model.GetSpModel;
import com.fimuz.mqmeet.api.loginusersetting.service.model.GetSrModel;
import com.fimuz.mqmeet.api.loginusersetting.service.model.UpdateBuildIdAndRetionIdSpModel;
import com.fimuz.mqmeet.api.loginusersetting.service.model.UpdateBuildIdAndRetionIdSrModel;
import com.fimuz.mqmeet.helper.mybatis.dao.HxzLoginuserSettingMapper;
import com.fimuz.mqmeet.helper.mybatis.model.HxzLoginuserSetting;
import com.fimuz.mqmeet.helper.mybatis.model.HxzLoginuserSettingExample;
import com.fosun.spr.core.base.CoBaseService;
import com.fosun.spr.core.utils.SprDaoUtils;

@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
@Service
public class LoginusersettingServiceImpl extends CoBaseService implements LoginusersettingService {
	@Resource
	private LoginusersettingDao loginusersettingDao;
	@Resource
	private HxzLoginuserSettingMapper hxzLoginuserSettingMapper;
 
	@Override
	public GetSrModel get(GetSpModel spModel) {
		GetSrModel srModel = new GetSrModel();
		HxzLoginuserSettingExample example = new HxzLoginuserSettingExample();
		HxzLoginuserSettingExample.Criteria c = example.createCriteria();
		c.andLoginuserIdEqualTo(spModel.getSessionUserId());
		c.andIsDeletedEqualTo(IS_DELETED_N);
		HxzLoginuserSetting record = (HxzLoginuserSetting)SprDaoUtils.getRowByExample(hxzLoginuserSettingMapper, example);
		if(record!=null){
			cglibCopyProperties(record, srModel, true);
		}		
		return srModel;
	}	
	@Override
	public UpdateBuildIdAndRetionIdSrModel updateBuildIdAndRetionId(UpdateBuildIdAndRetionIdSpModel spModel) {
		UpdateBuildIdAndRetionIdSrModel srModel = new UpdateBuildIdAndRetionIdSrModel();
		HxzLoginuserSettingExample example = new HxzLoginuserSettingExample();
		HxzLoginuserSettingExample.Criteria c = example.createCriteria();
		c.andLoginuserIdEqualTo(spModel.getSessionUserId());
		c.andIsDeletedEqualTo(IS_DELETED_N);
		HxzLoginuserSetting record = (HxzLoginuserSetting)SprDaoUtils.getRowByExample(hxzLoginuserSettingMapper, example);
		if(record==null){
			record = new HxzLoginuserSetting();
			cglibCopyProperties(spModel,record,true);
			record.setLoginuserId(spModel.getSessionUserId());
			record.setTeamId(spModel.getSessionTeamId());
			SprDaoUtils.insert(hxzLoginuserSettingMapper, record);  
		}else{
			cglibCopyProperties(spModel,record,true);
			record.setLoginuserId(spModel.getSessionUserId());
			record.setTeamId(spModel.getSessionTeamId());			
			SprDaoUtils.updateByPrimaryKey(hxzLoginuserSettingMapper, record);
		}
		return srModel;
	}	
 	
}
